<!--
 * @Author: your name
 * @Date: 2021-08-22 14:18:08
 * @LastEditTime: 2021-08-25 16:25:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hmmm-hm86-hmdytt\src\module-hmmm\components\subjects-add.vue
-->
<template>
  <div class="container">
    <!-- Form -->

    <el-dialog title="新增学科" :visible.sync="dialogFormVisible">
      <el-form :model="form" :rules="rules" ref="addd">
        <el-form-item label="学科名称" prop="subjectname">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-switch
          style="display: block"
          v-model="form.value2"
          active-color="#13ce66"
          inactive-color="pink"
          inactive-text="是否显示"
        >
        </el-switch>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="jia">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "subjectAdd",
  methods: {
    add() {
      this.dialogFormVisible = true;
    },
    async jia() {
      if (!this.form.name) {
        return this.$message("不能为空");
      }
      this.$emit("jia", this.form);
      this.$refs.addd.resetFields();
      console.log(this.form);
      this.dialogFormVisible = false;
      // this.dialogFormVisible = false;
      // const res = await add(this.subjectName, this.isFrontDisplay);
      // console.log(res);
      this.$nextTick(() => {
        this.$refs.addd.clearValidate();
      });
    }
  },
  data() {
    return {
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
        value2: true
      },
      rules: {
        subjectname: [
          {
            required: true,
            message: "用户姓名不能为空",
            trigger: ["blur", "change"]
          },
          {
            min: 1,
            max: 4,
            message: "用户姓名为1-4位",
            trigger: ["blur", "change"]
          }
        ]
      }
    };
  }
};
</script>

<style scoped lang="less"></style>
